import js from '@eslint/js'
import pluginVue from 'eslint-plugin-vue'
import vueEslintParser from 'vue-eslint-parser'
import tsParser from '@typescript-eslint/parser'
import globals from 'globals'
// 可以自动对 import 语句进行排序和分组，使代码更整洁
import importSort from 'eslint-plugin-simple-import-sort'

export default [
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        computed: 'readonly',
        defineEmits: 'readonly',
        defineExpose: 'readonly',
        defineProps: 'readonly',
        onMounted: 'readonly',
        onUnMounted: 'readonly',
        reactive: 'readonly',
        ref: 'readonly',
        shallowRef: 'readonly',
        shallowReactive: 'readonly',
        toRef: 'readonly',
        toRefs: 'readonly',
        watch: 'readonly',
        watchEffect: 'readonly'
      }
    },
    name: 'xxx/vue/setup',
    plugins: {
      vue: pluginVue
    }
  },
  {
    rules: {
      ...js.configs.recommended.rules,
      ...pluginVue.configs['flat/recommended'].rules,
      'simple-import-sort/imports': 'error', // 对 imports 排序
      'simple-import-sort/exports': 'error' // 对 exports 排序（可选）
    },
    files: ['**/*.{ts,tsx,vue}'],
    languageOptions: {
      parser: vueEslintParser,
      parserOptions: {
        extraFileExtensions: ['.vue'],
        ecmaVersion: 'latest', // ES 最新语法
        sourceType: 'module', // 模块化代码
        ecmaFeatures: {
          jsx: true // 支持 JSX（如使用）
        },
        parser: tsParser,
        project: []
      }
    },
    plugins: { vue: pluginVue, 'simple-import-sort': importSort }
  }
]
